package wd

import (
	"app/wd/gomysql"
	"fmt"

	"gorm.io/gorm"
)

type _Mysql struct {
	Conn *gomysql.Conn
	DB   *gorm.DB
}

func initMysql() {
	conf := App.Config.GetStringMapString("db")
	dbConf := &gomysql.Conn{
		ConfName: conf["conf_name"],
		Host:     conf["host"],
		Port:     conf["port"],
		User:     conf["user"],
		Pwd:      conf["pwd"],
		Database: conf["database"],
		Prefix:   conf["prefix"],
	}
	db, err := gomysql.NewClient(dbConf, App.SysLog)
	if err != nil {
		panic(fmt.Errorf("fatal error db connection: %w", err))
	}
	App.Mysql[dbConf.ConfName] = &_Mysql{
		Conn: dbConf,
		DB:   db,
	}
}
